package com.mall.product.consumer;

import com.alibaba.fastjson.JSON;
import com.mall.common.domain.MallProductSpell;
import com.mall.common.domain.MallUser;
import com.mall.common.result.Result;
import com.mall.product.feign.SystemFeignService;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author wangy
 * @version 1.0
 * @description: TODO
 */
@Component
public class SmsConsumer {
    @Resource
    private SystemFeignService systemFeignService;
    @RabbitListener(queuesToDeclare = {@Queue("sendCode")})
    public void sendATextMessage(String message){
        MallProductSpell mallProductSpell = JSON.parseObject(message, MallProductSpell.class);
        Result<MallUser> userResult = systemFeignService.findUserById(mallProductSpell.getSponsor());
        //TODO 打印短信内容
        System.out.println("手机号:"+userResult.getData().getPhone()+" \n" +
                "内容:你的"+mallProductSpell.getProductName()+"拼单已成功！" );
    }
    @RabbitListener(queuesToDeclare = {@Queue("sendATextMessage")})
    public void sendATextMessage2(String message){
        MallProductSpell mallProductSpell = JSON.parseObject(message, MallProductSpell.class);
        Result<MallUser> userResult = systemFeignService.findUserById(mallProductSpell.getSponsor());
        //TODO 打印短信内容
        System.out.println("手机号:"+userResult.getData().getPhone()+" \n" +
                "内容:你的"+mallProductSpell.getProductName()+"拼单失败！" );
    }
}
